package me.zhengjie.modules.hanzi.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.hanzi.domain.HanziCharacter;
import me.zhengjie.modules.hanzi.service.HanziService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import me.zhengjie.utils.Result;

@Slf4j
@Tag(name = "汉字管理", description = "汉字基本信息相关接口")
@RestController
@RequestMapping("/api/characters")
@RequiredArgsConstructor
public class CharacterController {
    private final HanziService hanziService;

    @Operation(summary = "获取汉字列表")
    @GetMapping
    public Result<List<HanziCharacter>> getCharacters(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int limit,
            @RequestParam(required = false) String level) {
        Page<HanziCharacter> characterPage = hanziService.getCharacters(page, limit, level);
        return Result.ok(characterPage.getRecords(), characterPage.getTotal(), page, limit);
    }

    @Operation(summary = "获取单个汉字详情")
    @GetMapping("/{character}")
    public Result<HanziCharacter> getCharacter(@PathVariable String character) {
        HanziCharacter hanzi = hanziService.getCharacter(character);
        if (hanzi == null) {
            return Result.error("汉字不存在");
        }
        return Result.ok(hanzi);
    }

    @Operation(summary = "获取每日汉字")
    @GetMapping("/daily")
    public Result<HanziCharacter> getDailyCharacter() {
        return Result.ok(hanziService.getDailyCharacter());
    }
} 